package com.mediastory.spsserver.guide.dao.impl;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.RowBounds;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository;

import com.mediastory.spsserver.guide.dao.GuideDao;
import com.mediastory.spsserver.guide.domain.Guide;

@Repository
public class GuideDaoImpl extends SqlSessionDaoSupport  implements GuideDao {

	public GuideDaoImpl() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public List<Guide> SelectList(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Integer page = (Integer)condition.get("page");
		Integer maxnum = (Integer)condition.get("maxnum");
		
		List<Guide> result = null;
		if(page != null && maxnum != null){
			RowBounds rb = new RowBounds(page, maxnum);
			result = getSqlSession().selectList("Guide.selectList", condition, rb);
		}else{
			result = getSqlSession().selectList("Guide.selectList", condition);
		}
		
		return result;
	}
	
	@Override
	public Integer SelectListTotalCnt(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Integer result = getSqlSession().selectOne("Guide.selectListTotalCnt", condition);
		return result;
	}

	@Override
	public Guide select(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		Guide result = (Guide)(getSqlSession().selectOne("Guide.select", condition)); 
		return result;
	}
	
	@Override
	public Integer selectIdx(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		Integer result = getSqlSession().selectOne("Guide.selectIdx", condition); 
		return result;
	}


	@Override
	public Guide insert(Guide guide) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().insert("Guide.insert", guide);
		return guide;
	}

	@Override
	public Guide update(Guide guide) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().update("Guide.update", guide);
		return guide;
	}

	@Override
	public int delete(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().update("Guide.delete", condition);
		return result;
	}

}
